<template>
	<view class="activity">
		<comHead :isLeft="true" :isRight="false"></comHead>
		<view class="videoImg">
			<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
				:duration="duration">
				<swiper-item class="swiper-item">
					<image :src="getImg(detail.image)" mode="aspectFill"></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="ms">
			<!-- #ifdef H5 -->
			<view class="share">
				<image @click="messageFun('share')" src="https://siha.vxmeng.com/static/more/share.png" mode="widthFix"></image>
				<text>{{$t('sjzx.fx')}}</text>
			</view>
			<!-- #endif -->
			<!-- #ifndef H5 -->
			<button class="share" open-type="share">
				<image src="https://siha.vxmeng.com/static/more/share.png" mode="widthFix"></image>
				<text>{{$t('sjzx.fx')}}</text>
			</button>
			<!-- #endif -->
						
			<view class="tit">
				<text>{{detail.name}}</text>
<!-- 				<view class="imgs">
					<image v-for="(item,index) in detail.score/2" src="https://siha.vxmeng.com/static/more/on.png"
						mode="widthFix"></image>
					<image v-for="(item,index) in 5-detail.score/2" src="https://siha.vxmeng.com/static/more/no.png"
						mode="widthFix"></image>
				</view>
				<text>{{Number(detail.score).toFixed(1)}}</text> -->
			</view>
			<view class="text">
				<text>{{detail.blurb}}</text>
			</view>

			<view class="tit">
				<text>{{$t('gdjj.wjdp')}}</text>
			</view>
			<view class="userBox">
				<view class="l">
					<image :src="getImg(userinfo.avatar)" mode="aspectFill"></image>
					<view class="user">
						<text>{{userinfo.nickname}}</text>
						<text @click="changeScorePop(true)">{{$t('gdjj.fbnddp')}}</text>
					</view>
				</view>
				<view class="r">
					<text>{{Number(detail.score).toFixed(1)}}</text>
					<view class="imgs">
						<image v-for="(item,index) in parseInt(detail.score/2)" src="https://siha.vxmeng.com/static/more/on.png"
							mode="widthFix"></image>
						<image v-for="(item,index) in 5-parseInt(detail.score/2)" src="https://siha.vxmeng.com/static/more/no.png"
							mode="widthFix"></image>
					</view>
					<text>{{$t('gdjj.gj')}}{{remark.length}}{{$t('gdjj.g1750pj')}}</text>
				</view>
			</view>
			<view class="list">
				<view class="item" v-for="(item,index) in remark">
					<view class="t">
						<view class="l">
							<image :src="getImg(item.user_avatar)" mode="aspectFill"></image>
							<view class="user">
								<text>{{item.user_nickname}}</text>
								<text>{{item.create_time}}</text>
							</view>
						</view>
						<view class="r">
							<view class="imgs">
								<image v-for="(item,index) in parseInt(item.score/2)" src="https://siha.vxmeng.com/static/more/on.png"
									mode="widthFix"></image>
								<image v-for="(item,index) in 5-parseInt(item.score/2)" src="https://siha.vxmeng.com/static/more/no.png"
									mode="widthFix"></image>
							</view>
						</view>
					</view>
					<view class="b">
						<view>
							{{item.remark}}
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="btn" @click="profile()">
			<text>{{$t('gdjj.ksgk')}}</text>
		</view>
		
		<view class="scorePop" v-if="isScorePop">
			<view class="score">
				<view class="s">
					<image @click="changeScorePop(false)" src="https://siha.vxmeng.com/static/index/close.png" mode="widthFix"></image>
				</view>
				<view class="tit">{{detail.name}}</view>
				<view class="imgs">
					<image v-for="(item,index) in 5" :src="(index+1)*2>score?'https://siha.vxmeng.com/static/more/no.png':'https://siha.vxmeng.com/static/more/on.png'"
						mode="widthFix" @click="onScoring(index)"></image>
				</view>
				<view class="intro">{{$t('gdjj.lxndpf')}}</view>
				<!-- <input type="text" v-model="remarkVal" :placeholder="$t('gdjj.sljb')"/> -->
				<textarea type="text" @input="onCheck" v-model="remarkVal" :placeholder="$t('gdjj.sljb')"></textarea>
				<view class="btn" :class="isDis?'dis':''" @click="onScore">{{$t('grzx.tj')}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isDis: true,
				isScorePop: false,
				remarkVal: '',
				userinfo: {},
				detail: {},
				remark: [],
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				id: '',
				score: 0,
			}
		},
		onLoad(options) {
			this.id = options.id
			this.getEpisodeDetail()
			this.getUserinfo()
			this.getEpisodeRemark()
		},
		methods: {
			async onScore(){
				if(this.isDis) return
				const res = await this.$myRequest({
					url: 'api/episode/doAddEpisodeRemark',
					data: {
						episode_script_id: this.detail.id,
						star_num: this.score/2,
						remark: this.remarkVal
					}
				})
				if(res.code == 1){
					this.getEpisodeRemark()
					this.isScorePop = false
					this.$tools.showTx(this.$t('gdjj.dpcg'))
				}
			},
			changeScorePop(e){
				this.isScorePop = e
			},
			onScoring(index){
				this.score = (index + 1)*2
				this.onCheck()
			},
			onCheck(){
				if(this.score==0 || this.remarkVal.trim()==''){
					this.isDis = true
				}else{
					this.isDis = false
				}
			},
			async profile() {
				const res = await this.$myRequest({
					url: 'api/user/profile',
					data: {
						episode_info_id: this.detail.id
					}
				})
				if (res.code == 1) {
					console.log(res)
					// #ifdef MP-WEIXIN
					if (this.detail.video_type == 2) {
						this.comLink('/pages/index/siha?id=' + this.detail.episode_info_id)
					} else {
						this.comLink('/pages/index/siha2?id=' + this.detail.episode_info_id)
					}
					// #endif
					// #ifndef MP-WEIXIN
					this.comLink('/pages/index/siha_dy?id=' + this.detail.episode_info_id)
					// #endif
				}
			},
			async getUserinfo() {
				const res = await this.$myRequest({
					url: 'api/user/index',
					data: {}
				})
				if (res.code == 1) {
					console.log(res)
					this.userinfo = res.data
				}
			},
			async getEpisodeDetail() {
				const res = await this.$myRequest({
					url: 'api/episode/getEpisodeDetail',
					data: {
						episode_script_id: this.id
					}
				})
				if (res.code == 1) {
					console.log(res)
					this.detail = res.data
				}
			},
			async getEpisodeRemark() {
				const res = await this.$myRequest({
					url: 'api/episode/getEpisodeRemark',
					data: {
						episode_script_id: this.id
					}
				})
				if (res.code == 1) {
					console.log(res)
					this.remark = res.data
				}
			},
		}
	}
</script>

<style lang="less" scoped>
	.activity {
		width: 100%;
		display: flex;
		flex-direction: column;
		min-height: 100vh;
		background-color: rgb(13, 10, 31);

		// align-items: center;
		.videoImg {
			width: 100%;
			height: 502rpx;
			position: absolute;
			top: 0;
			left: 0;

			.swiper {
				width: 100%;
				height: 502rpx;
			}

			.swiper-item {
				width: 750rpx;
				height: 502rpx;
				position: relative;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.ms {
			position: absolute;
			top: 502rpx;
			left: 0;
			width: 100%;
			padding: 0 30rpx;
			box-sizing: border-box;
			height: calc(100vh - 502rpx);
			overflow: auto;
			
			.share{
				position: absolute;
				right: 30rpx;
				top: 20rpx;
				display: flex;
				align-items: center;
				margin: 0;
				border: none;
				flex-direction: column;
				color: #fff;
				font-size: 26rpx;
				image {
					width: 44rpx;
				}
				&::after{
					border: none;
				}
			}

			.tit {
				font-size: 32rpx;
				color: #fff;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 50rpx;
				
				.imgs {
					margin-left: 20rpx;
				
					image {
						width: 24rpx;
						margin-left: 10rpx;
					}
				}

				text {
					&:nth-child(1) {
						width: 56%;
					}

					&:nth-child(3) {
						color: #FFD673;
						font-size: 40rpx;
					}
				}
			}

			.text {
				color: #D8D8D8;
				font-size: 24rpx;
				margin-top: 30rpx;
				line-height: 1.5;
			}

			.userBox {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 10rpx;
				padding: 24rpx 0;

				.l {
					display: flex;
					align-items: center;

					image {
						width: 96rpx;
						height: 96rpx;
						border-radius: 50%;
						margin-right: 20rpx;
					}

					.user {
						display: flex;
						flex-direction: column;

						text {
							color: #D8D8D8;
							font-size: 28rpx;

							&:nth-child(2) {
								font-size: 24rpx;
								color: #A2A2A2;
								margin-top: 10rpx;
							}
						}
					}
				}

				.r {
					color: #FFD673;
					font-size: 20rpx;
					display: flex;
					align-items: flex-end;
					flex-direction: column;
					position: relative;	

					text {
						color: #D8D8D8;
						&:first-child{
							position: absolute;
							top: 0;
							left: -110rpx;
							font-size: 60rpx;
							color: #fff;
						}
					}

					.imgs {
						margin-bottom: 6rpx;

						image {
							width: 24rpx;
							margin-left: 6rpx;
						}
					}
				}
			}

			.list {
				padding-bottom: 120rpx;
				.item {
					width: 100%;
					padding: 20rpx 40rpx;
					box-sizing: border-box;
					background-color: rgb(28, 26, 50);
					margin-bottom: 30rpx;
					border-radius: 36rpx;
					padding: 32rpx;
					.t {
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-bottom: 20rpx;

						.l {
							display: flex;
							align-items: center;

							image {
								width: 72rpx;
								height: 72rpx;
								border-radius: 50%;
								margin-right: 20rpx;
							}

							.user {
								display: flex;
								flex-direction: column;

								text {
									color: #D8D8D8;
									font-size: 24rpx;

									&:nth-child(2) {
										font-size: 20rpx;
										color: #A2A2A2;
										margin-top: 10rpx;
									}
								}
							}
						}

						.r {
							color: #FFD673;
							font-size: 32rpx;
							display: flex;
							align-items: baseline;

							.imgs {
								margin-left: 20rpx;

								image {
									width: 24rpx;
									margin-left: 10rpx;
								}
							}
						}
					}

					.b {
						display: flex;
						justify-content: space-between;

						image {
							width: 224rpx;
							height: 168rpx;
							border-radius: 10rpx;
						}

						view {
							display: inline-flex;
							width: 100%;
							line-height: 1.6;
						}

						font-size: 24rpx;
						color: #D8D8D8;
						opacity: 0.8;
					}
				}
			}
		}

		&>.btn {
			position: fixed;
			left: 0px;
			bottom: 0px;
			width: 100%;
			height: 166rpx;
			display: flex;
			align-items: center;
			justify-content: center;

			text {
				display: inline-flex;
				// width: 560rpx;
				width: calc(100vw - 60rpx);
				height: 96rpx;
				background: linear-gradient(90deg, rgba(98, 182, 252, 0.95) 5%, rgba(95, 88, 253, 0.95) 100%);
				align-items: center;
				justify-content: center;
				border-radius: 60rpx;
				color: #fff;
				font-weight: 700;
				font-size: 40rpx;
			}
		}
		
		.scorePop{
			width: 100vw;
			height: 100vh;
			background-color: rgba(0, 0, 0, .5);
			position: fixed;
			top: 0;
			left: 0;
		}
		
		.score{
			width: 100vw;
			height: 60vh;
			padding: 40rpx;
			color: #D8D8D8;
			font-size: 28rpx;
			position: absolute;
			bottom: 0;
			left: 0;
			background-color: #101722;
			border-radius: 16rpx 16rpx 0 0;
			display: flex;
			flex-direction: column;
			align-items: center;
			.s{
				text-align: end;
				font-size: 20rpx;
				color: #AAAAAA;
				image{
					width: 40rpx;
					position: absolute;
					top: 30rpx;
					right: 30rpx;
				}
			}
			.tit{
				font-size: 28rpx;
				text-align: center;
			}
			.intro{
				font-size: 28rpx;
				margin-top: 20rpx;
			}
			.imgs{
				margin-top: 60rpx;
				image {
					width: 50rpx;
					margin-left: 16rpx;
				}
			}
			textarea{
				width: 100%;
				border-radius: 28rpx;
				background: #484A4D;
				padding: 20px;
				box-sizing: border-box;
				margin-top: 40rpx;
			}
			.btn{
				width: calc(100% - 80rpx);
				height: 90rpx;
				line-height: 90rpx;
				text-align: center;
				border-radius: 10rpx;
				background: linear-gradient(270deg, #5F58FD 0%, #62B6FC 100%);
				position: absolute;
				bottom: 60rpx;
				&.dis{
					background: #767B82;
				}
			}
		}
	}
</style>